<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                餐饮名称：<input type="text" name="goodsName"/>
                            </li>
                            <li>
                                餐饮类型：<select name="goodsType" th:with="type=${@dict.getType('goods_type_item')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:goodsInfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:goodsInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:goodsInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:goodsInfo:remove')}]];
        var prefix = ctx + "system/goodsInfo";

        var datas = [[${@dict.getType('goods_type_item')}]];
        var datas2 = [[${@dict.getType('goods_status')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                search: false,
                showSearch:false,
                showRefresh:false,
                showColumns:false,
                showToggle:false,
                showExport:false,
                modalName: "餐饮",
                columns: [{
		            checkbox: true
		        },
                {
                    field : 'userName',
                    title : '店铺' ,
                    width: '100'
                },
                {
                    field : 'imgUrl',
                    title : '首图',
                    formatter: function(value, row, index) {
                        return '<img src="'+value+'" style="width: 90px;height: 90px;"/>';
                    }
                },
				{
					field : 'goodsId', 
					title : '餐饮编号' ,
                    visible: false
				},
				{
					field : 'goodsName', 
					title : '餐饮名称' ,
                    width: '250'
				},
				{
					field : 'briefInformation', 
					title : '简介说明',
                    visible: false
				},
				{
					field : 'goodsType', 
					title : '类型' ,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
				},
                {
                    field : 'status',
                    title : '状态' ,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas2, value);
                    }
                },
				{
					field : 'attr1', 
					title : '原料',
                    visible: false
				},
				{
					field : 'attr2', 
					title : '品牌',
                    visible: false
				},
				{
					field : 'goodsPrice', 
					title : '价格' ,
                    formatter: function(value, row, index) {
					    return '￥'+value;
                    }
				},
                {
                    field : 'goodsLeft',
                    title : '库存'
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
                        actions.push('<a class="btn btn-link btn-sm" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.goodsId + '\')"><i class="fa fa-eye"></i>查看</a> ');
		            	actions.push('<a class="btn btn-link btn-sm ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		            	if(row.status == 0){
                            actions.push('<a class="btn btn-link btn-sm ' + editFlag + '" href="javascript:void(0)" onclick="editStatus(\'' + row.goodsId + '\',1)"><i class="fa fa-arrow-down"></i>下架</a> ');
                        }else if(row.status == 1){
                            actions.push('<a class="btn btn-link btn-sm ' + editFlag + '" href="javascript:void(0)" onclick="editStatus(\'' + row.goodsId + '\',0)"><i class="fa fa-arrow-up"></i>上架</a> ');
                        }
                        actions.push('<a class="btn btn-link btn-sm ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

        function editStatus(goodsId,status) {
            var json = {0:"上架",1:"下架"};
            $.modal.confirm("您确定"+json[status]+"吗？",function () {
               $.operate.submit(prefix+"/edit","post","json",{goodsId:goodsId,status:status});
            });
        }
    </script>
</body>
</html>